import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

// 导入路由表
import constant from './router'
// 导入常量路由表
export const constantRoutes = constant

//异步挂载的路由
//动态需要根据权限加载的路由表 
// meta: { role: ['admin','super_editor'] }, //页面需要的权限
export const asyncRoutes = [
    {
      path: "/admin",
      component: Layout,
      redirect: "/admin/list",
      name: 'Admin',
      meta: {
        title: '用户管理',
        icon: 'account'
      },
      children: [
        {
          path: 'list',
          component: () => import('@/views/admin/list'),
          name: '用户列表',
          meta: { title: '用户列表', icon: 'student' ,role: ['admin']}
        },
        {
          path: 'add',
          component: () => import('@/views/admin/add'),
          name: '新增用户',
          meta: { title: '新增用户', icon: 'addStudent',role: ['admin'] }
        },
        {
          path: 'edit',
          name: '修改用户',
          hidden:true,
          meta: { title: '修改用户', icon: 'student', role: ['admin']}
        }
      ]
    },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
  ];


  const createRouter = () => new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  // 重置动态路由
  router.matcher = newRouter.matcher 
}


export default router
